/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.comut.crud;

import com.comut.crud.ejb.interfaces.remote.IUtilActionRemote;
import java.util.ResourceBundle;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.RequestScoped;
import javax.naming.InitialContext;
import org.apache.log4j.Logger;


/**
 *
 * @author asantos
 */

@ManagedBean(name="UtilB")
@RequestScoped
public class UtilB {
    private static Logger _logger = Logger.getLogger(UtilB.class.getName());
    final String jndiName = ResourceBundle.getBundle("jndi").getString("utilBeanRemote");
    
    private String welcomeMessage = "";

    /**
     * Creates a new instance of UtilB
     */
    public UtilB() {
       
    }

    public String getWelcomeMessage() {
        return welcomeMessage;
    }

    public void setWelcomeMessage(String welcomeMessage) {
        this.welcomeMessage = welcomeMessage;
    }
    
    public String insertInMailChimp(){
        try {           
            javax.naming.Context ic = new InitialContext();
            Object obj = ic.lookup(jndiName);
            IUtilActionRemote iuar = (IUtilActionRemote) obj;
            iuar.insertUsersInMailChimp();
            welcomeMessage = "Users are now in MailChimp!!";
            _logger.info("Users are now in MailChimp!!");
        
        } catch (Exception ex) {
           _logger.error(ex);
        }
        return null;
    }
    
}
